package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.blnocontactvo.BlnoContactCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnocontactvo.BlnoContactPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.blnocontactvo.BlnoContactRespVO;
import com.cmc.cloud.cmclink.doc.vo.blnocontactvo.BlnoContactUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.BlnoContactDO;
import com.cmc.cloud.cmclink.doc.service.BlnoContactService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 目的港代理联系方式维护")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/blnoContact")
@Validated
public class BlnoContactController {

    @Resource
    private BlnoContactService blnoContactService;

    @Operation(summary = "创建目的港代理联系方式维护")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:setContactAddress:add')")
    public CommonResult<Void> createBlnoContact(@Valid @RequestBody BlnoContactCreateReqVO createReqVO) {
        blnoContactService.createBlnoContact(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新目的港代理联系方式维护")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:setContactAddress:edit','doc:setContactAddress:save'})")
    public CommonResult<Void> updateBlnoContact(@Valid @RequestBody BlnoContactUpdateReqVO updateReqVO) {
        blnoContactService.updateBlnoContact(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除目的港代理联系方式维护")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:setContactAddress:delete')")
    public CommonResult<Void> deleteBlnoContact(@PathVariable("id") Long id) {
        blnoContactService.deleteBlnoContact(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得目的港代理联系方式维护")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<BlnoContactRespVO> getBlnoContact(@PathVariable("id") Long id) {
        BlnoContactDO blnoContact = blnoContactService.getBlnoContact(id);
        return CommonResult.success(BeanUtil.copyProperties(blnoContact, BlnoContactRespVO.class));
    }

    @Operation(summary = "获得目的港代理联系方式维护列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<BlnoContactRespVO>> getBlnoContactList(@RequestParam("ids") Collection<Long> ids) {
        List<BlnoContactDO> list = blnoContactService.getBlnoContactList(ids);
        return CommonResult.success(BeanUtil.copyToList(list,BlnoContactRespVO.class));
    }

    @Operation(summary = "获得目的港代理联系方式维护分页")
    @UseResponsePropertyAdvice
    @PostMapping("/getPage")
    @PreAuthorize("@ss.hasPermission('doc:setContactAddress:search')")
    public CommonResult<PageResult<BlnoContactRespVO>> getBlnoContactPage(@Valid @RequestBody BlnoContactPageReqVO pageVO) {
        PageResult<BlnoContactDO> pageResult = blnoContactService.getBlnoContactPage(pageVO);
        List<BlnoContactRespVO> results = BeanUtil.copyToList(pageResult.getList(),BlnoContactRespVO.class);
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
